<?php
/**
 * Created by PhpStorm.
 * User: krystal
 * Date: 2019/6/17
 * Time: 14:53
 */

namespace app\common\model;


class ZhunlePhysicalStoreOrder extends Base
{
   protected $table = 'wechat_backup_07_18_14_43_00.zhunle_physical_store_order';

    /**
     * 获取用户当前分类下的所有订单
     * @param array $map
     * @return array
     */
   public function UserOrder($map=[])
   {
       $where =['uid'=>$map['uid']];
       switch ($map['type'])
       {
           case 1:
               $where['order_status'] =1;
               break;
           case 2:
               $where['order_status'] =['in',[1,2,3]];
               break;
           case 3:
               $where['order_status'] =4;
               break;
           case 0:
           default:
               $where['del_time'] = 0;
               break;
       }
      try{
         $orders =  $this
             ->where($where)
             ->order('create_time','DESC')
             ->paginate(10, false, ['page' => $map['page']])
             ->toArray();
      }catch (\Exception $e)
      {
         $orders=[];
      }

      return $orders;
   }

    /**
     * 获取订单详情
     * @param array $map
     * @return array|null
     */
   public function OrderDetail($map=[])
   {
      try{
          $order = $this->where('id',$map['oid'])->findOrFail()->toArray();
      }catch (\Exception $e)
      {
          $order = null;
      }
      return $order;
   }

    /**
     * 删除订单
     * @param array $map
     * @return bool
     */
   public function DelOrder($map=[])
   {
       try{
           $this->isUpdate(true)->save(['del_time'=>time()],['id'=>$map['oid']]);
       }catch (\Exception $e)
       {
          return false;
       }
       return true;
   }
}